package Model;

import java.util.Arrays;

/*
 * According to the message flags create a sub-class of BaseMessage
 * and handle its push/pull operations
 * */
public class RequestHandler 
{	
	// relevant sub-class according to flags
	private BaseMessage m_Message;
	
	public RequestHandler(byte[] b) 
	{		
		// extract first byte - that byte is for the flags
		byte[] rest = Arrays.copyOfRange(b, 1, b.length);
		
		switch (b[0]) 
		{
			// retrieve the PO public params
			case 0:
				m_Message = new PPMessage();	
				break;
			
			// push and pull message (including dummies)
			default:
				m_Message = new PushAndPullMessage(rest);
				break;
		}
	}
	
	public byte[] pull() 
	{
		return m_Message.pull();
	}
	
	public void push() 
	{		
		m_Message.push();
	}
}
